package com.yiwenup.struct._01_linear.stack;

import com.yiwenup.struct._01_linear.array.DynamicArray2;
import com.yiwenup.struct._01_linear.base.List;

/**
 * 栈结构：复用动态数组结构
 */
public class Stack<E> {

    private List<E> list = new DynamicArray2<>();

    public void clear() {
        list.clear();
    }

    public int size() {
        return list.size();
    }

    public boolean isEmpty() {
        return list.isEmpty();
    }

    public E pop() {
        return list.remove(list.size() - 1);
    }

    public void push(E ele) {
        list.add(ele);
    }

    public E top() {
        return list.get(list.size() - 1);
    }
}
